<template>
  <div class="toast"
       :class="{
        active_default : type === 'default',
        active_success: type === 'success',
        active_failure: type === 'failure',
        active_alert: type === 'alert'}" v-show="isShow">
    <span class="el-icon-info" v-show="type === 'default'"></span>
    <span class="el-icon-success" v-show="type === 'success'"></span>
    <span class="el-icon-error" v-show="type === 'failure'"></span>
    <span class="el-icon-warning" v-show="type === 'alert'"></span>
    <div class="message">{{message}}</div>
  </div>
</template>

<script>
  export default {
    name: "Toast",
    data() {
      return {
        message: '哈哈哈哈哈哈',
        isShow: false,
        type: 'default',
      }
    },
    methods: {
      show(message, type='default', duration=1000) {
        this.message = message
        this.type = type
        this.isShow = true
        setTimeout(() => {
          this.message = ''
          this.isShow = false
          this.type = 'default'
        }, duration)
      }
    }
  }
</script>

<style scoped>
  .toast {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 10002;
    transform: translate(-50%, -50%);
    width: 450px;
    height: 80px;
    padding-left: 50px;
    border-radius: 10px;
    background-color: #fff;
    box-shadow: 0 0 5px rgba(0,0,0, .1);
    text-align: center;
    line-height: 80px;
    font-size: 18px;
    color: #2c4168;
  }

  span[class*='el-icon'] {
    float: left;
    margin-right: 15px;
    line-height: 80px;
    font-size: 22px;
  }

  .message {
    float: left;
  }

</style>
